function [f,mu0_m,gam_m,iota_m,b_m,b_f,zeta_m,zeta_f,scost_m,scost_f,lam_m,mu0_f,gam_f,iota_f,lam_f] = modelobjective_endosearch(x,mustar_m,mustar_f,sigstar_m,sigstar_f,bet,capT,capT2,Nw,Nwlong,...
    cumcomp_m_dat,cumcomp_f_dat,beliefs_m_dat,beliefs_f_dat,proboffer_m_dat,proboffer_f_dat,cumsum_m_dat,cumsum_f_dat,lam_m,lam_f,zeta_m,zeta_f)

% startval       = [ log(mu0_m-mustar_m) log(gam_m)  log(iota_m-1.1) ...
%        log(b_m./lognstat(mustar_m,sigstar_m))  log(scost_m) log(mu0_f-mustar_f) log(gam_f) log(iota_f-iota_m) ] ;
% 
mu0_m 	= mustar_m+exp(x(1)) ;
gam_m   = exp(x(2)) ;
iota_m  = 1.01+exp(x(3)) ;
b_m     = sin(x(4))^2*lognstat(mustar_m,sigstar_m) ;
scost_m = exp(x(5)) ;
scost_f = exp(x(5)) ;

mu0_f 	= mustar_f+exp(x(6)) ;
gam_f   = gam_m+exp(x(7)) ; % force women to learn faster?
% gam_f   = exp(x(7)) ;

iota_f  = iota_m+exp(x(8)) ; % women are more risk averse than men.
b_f     = sin(x(4))^2*lognstat(mustar_f,sigstar_f) ; % force the share to be the same

%b_f     = sin(x(4))^2*lognstat(mustar_m,sigstar_m) ; % force these to be the same


if isnan(iota_m) || isnan(iota_f)
    display('problem')
end

[wstar_m,cumcomp_m,cumulsum_m,meanacceptedw_m,expectedw_m,proboffer_m,probs_m,rej_atleast1_m,rejrate_m,fdist_m,fval_m] = ...
    modelsolve_endosearch(iota_m,b_m,zeta_m,mu0_m,gam_m,mustar_m,sigstar_m,scost_m,lam_m,bet,capT,capT2,Nw,Nwlong,cumcomp_m_dat,beliefs_m_dat,proboffer_m_dat,cumsum_m_dat) ;

[wstar_f,cumcomp_f,cumulsum_f,meanacceptedw_f,expectedw_f,proboffer_f,probs_f,rej_atleast1_f,rejrate_f,fdist_f,fval_f] = ...
    modelsolve_endosearch(iota_f,b_f,zeta_f,mu0_f,gam_f,mustar_f,sigstar_f,scost_f,lam_f,bet,capT,capT2,Nw,Nwlong,cumcomp_f_dat,beliefs_f_dat,proboffer_f_dat,cumsum_f_dat) ;

 f = [fval_m fval_f]*[fval_m fval_f]' ;
